package com.ml.loan.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ml.loan.sys.dao.RoleMapper;
import com.ml.loan.sys.model.Role;
import com.ml.loan.sys.service.RoleService;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author wangfan
 * @since 2019-02-11
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Override
    public boolean checkAdmin() {
        QueryWrapper<Role> wrapper = new QueryWrapper<>();
        wrapper.select("role_id").eq("role_name", "管理员");
        List<Object> roleIds = listObjs(wrapper);
        for (Object roleId : roleIds) {
            if (SecurityUtils.getSubject().hasRole(String.valueOf(roleId))) {
                return true;
            }
        }
        return false;
    }
}
